package tech.aistar.corejava.day11;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Created by 李雨昂 on 2019/7/29.
 */
public class HashSetDemo {
    public static void main(String[] args) {
        Set<User> users = new HashSet<>();

        User u1 = new User(1,"tom");
        User u2 = new User(2,"jack");
        User u3 = new User(1,"james");//拒绝添加的
        User u4 = new User(3,"jack");
        User u5 = new User(4,"jamessss");

        users.add(u1);
        users.add(u2);
        users.add(u3);
        users.add(u4);
        users.add(u5);

        //遍历
        Iterator<User> userIterator = users.iterator();
        while(userIterator.hasNext()){
            System.out.println(userIterator.next());
        }
    }
}
